n1 = int(input())
n = n1
k = 0
g = 0
if n > 999 and n < 10000:
    for i in range(2, n):
        if n%i == 0:
            g+=1
    if g == 0:
        if n > k:
            k = n


            
    g = 0
    n1 = str(n1)
    n = n1[0]
    n = int(n)
    for i in range(2, n):
        if n%i == 0:
            g+=1
    if g == 0:
        if n > k:
            k = n


            
    g = 0
    n = n1[1]
    n = int(n)
    for i in range(2, n):
        if n%i == 0:
            g+=1
    if g == 0:
        if n > k:
            k = n


            
    g = 0
    n = n1[2]
    n = int(n)
    for i in range(2, n):
        if n%i == 0:
            g+=1
    if g == 0:
        if n > k:
            k = n


            
    g = 0
    n = n1[3]
    n = int(n)
    for i in range(2, n):
        if n%i == 0:
            g+=1
    if g == 0:
        if n > k:
            k = n

    
            
    g = 0
    n = n1[0:2]
    n = int(n)
    for i in range(2, n):
        if n%i == 0:
            g+=1
    if g == 0:
        if n > k:
            k = n


            
    g = 0
    n = n1[1:3]
    n = int(n)
    for i in range(2, n):
        if n%i == 0:
            g+=1
    if g == 0:
        if n > k:
            k = n


            
    g = 0
    n = n1[2:4]
    n = int(n)
    for i in range(2, n):
        if n%i == 0:
            g+=1
    if g == 0:
        if n > k:
            k = n


            
    g = 0
    n = n1[0:3]
    n = int(n)
    for i in range(2, n):
        if n%i == 0:
            g+=1
    if g == 0:
        if n > k:
            k = n


            
    g = 0
    n = n1[1:4]
    n = int(n)
    for i in range(2, n):
        if n%i == 0:
            g+=1
    if g == 0:
        if n > k:
            k = n
    print(k)
else:
    print("0")
